IF OBJECT_ID('ssf.gbl_get_semaphore_locked_connection_count') IS NOT NULL
	DROP FUNCTION ssf.gbl_get_semaphore_locked_connection_count
GO

CREATE FUNCTION ssf.gbl_get_semaphore_locked_connection_count (
	@semaphore_name NVARCHAR(128)
)
RETURNS INT
AS
BEGIN
	RETURN (
		SELECT COUNT(*)
		FROM ssf.gbl_semaphore_connection WITH (NOLOCK)
		WHERE semaphore_name = @semaphore_name
		AND locked_by_spid IS NOT NULL
	)
END
GO
